//**********************************************************
// OSH
//**********************************************************
function OSH()
{
	var _this = this;
	var _osh = OSH.getHost().Osh;
	var _visible = _osh.Visible;
	var _mode;
	var _themeName = Configuration.getCurrent().Osh.Theme;

	this._ignoreKeys = new Array();	// the keys to ignore when they are received next time

	this.progDVB = null;
	this.navigator = new Navigator();
	this.mediaController = new MediaController(_osh.MediaController);

	this._suspendCount = 0;
	this._lastSuspendTime = null;
	this._refreshOnResume = false;

	// Events
	this.onModeChange = new Event();
	this.onShow = new Event();
	this.onHide = new Event();
	this.onKey = new Event();
	this.onCommand = new Event();
	this.onModeChanged = new Event();
	
	var _showEventSink = new EventSink(_osh, "Show", onShowHandler);
	var _hideEventSink = new EventSink(_osh, "Hide", onHideHandler);
	var _commandEventSink = new EventSink(_osh, "Command", onCommandHandler);
	var _modeChangedEventSink = new EventSink(_osh, "ModeChanged", onModeChangedHandler);

	this.initialize = function()
	{
		_mode = Mode.getMode(_osh.Mode);
	}

	function onShowHandler(sender, args)
	{
		// Get in sync in case the visibility was changed from outside.
		_visible = true;
		_this.fireOnShow();
	}

	function onHideHandler(sender, args)
	{
		// Get in sync in case the visibility was changed from outside.
		_visible = false;
		_this.fireOnHide();
	}

	function onCommandHandler(sender, args)
	{
		_this.processKeyOrCommandInternal(args.Command);
	}
	
	function onModeChangedHandler(sender, args)
	{
		_mode = Mode.getMode(args.Mode);
		_this.fireOnModeChange(args.Mode);
	}
	
	this.notifyScreenChange = function(screenName)
	{
		_osh.NotifyScreenChange(screenName);
	}
	
	this.getHost = function()
	{
		return OSH.getHost();
	}

	this.getMode = function()
	{
		return _mode;
	}

	this.setMode = function(mode)
	{
		_osh.Mode = mode; // _mode variable will be changed in onModeChangedHandler event handler
	}

	this.getVisible = function()
	{
		return _visible;
	}

	this.setVisible = function(visible)
	{
		if(_visible == visible)
			return;
		
		_visible = !!visible;
		window.top.log.writeln("OSH.setVisible(" + _visible + ")");
		_osh.Visible = _visible;
		// onShow & onHide events will be fired from onShowHandler()/onHideHandler() methods.
	}

	this.getThemeName = function()
	{
		return _themeName;
	}

	this.setThemeName = function(themeName)
	{
		_themeName = themeName;
	}

	this.show = function()
	{
		this.setVisible(true);
	}

	this.hide = function()
	{
		this.setVisible(false);
	}

	this.refresh = function()
	{
		window.top.log.writeln("OSH refreshing (suspendCount = " + this._suspendCount + ")...");
		
		if(this._suspendCount > 0)
		{
			this._refreshOnResume = true;
			return;
		}
		
		if(this.getVisible())
			_osh.Refresh();
		
		this._refreshOnResume = false;

		window.top.log.writeln("OSH refreshed.");
	}

	this.moveTo = function(x, y)
	{
		_osh.SetBounds(x, y, _osh.Width, _osh.Height);
	}

	this.resizeTo = function(width, height)
	{
		_osh.SetBounds(_osh.Left, _osh.Top, width, height);
	}
}
Type.registerType('OSH');

OSH.getCurrent = function()
{
	if(!OSH._current)
	{
		OSH._current = new OSH();
		OSH._current.initialize();
	}
	return OSH._current;
}

OSH.getHost = function()
{
	if(!OSH._oshHost)
		OSH._oshHost = GetObject("", "OSH.Host");
	return OSH._oshHost;
}

OSH.prototype.suspendLayout = function()
{
	if(this._suspendCount > 0 && (this._lastSuspendTime.valueOf() <  new Date().valueOf() - 15 * 1000))
	{
		window.top.log.error("Layout wasn't resumed after being suspended at " + this._lastSuspendTime + ".");
		this._suspendCount = 0;
	}

	this._suspendCount++;
	this._lastSuspendTime = new Date();
}

OSH.prototype.resumeLayout = function()
{
	if(this._suspendCount <= 0)
	{
		window.top.log.error("Suspend count is zero.");
		this._suspendCount = 0;
	}
	else
		this._suspendCount--;

	if(this._suspendCount == 0 && this._refreshOnResume)
		this.refresh();
}

OSH.prototype.getPlugin = function(pluginName)
{
	var pluginsFrame = window.top.frames["pluginsFrame"];
	if(pluginsFrame != null && pluginsFrame.location != null && pluginsFrame.document != null)
		return pluginsFrame.document.getElementById(pluginName);
}

OSH.prototype.fireOnModeChange = function(mode)
{
	var e = window.top.document.createEventObject();
	e.mode = mode;
	this.onModeChange.fire(this, e);
}

OSH.prototype.fireOnShow = function()
{
	var e = window.top.document.createEventObject();
	this.onShow.fire(this, e);
}

OSH.prototype.fireOnHide = function()
{
	var e = window.top.document.createEventObject();
	this.onHide.fire(this, e);
}

OSH.prototype.needToIgnoreKey = function(key)
{
	if(this._ignoreKeys.length > 0)
	{
		for(var i = 0; i < this._ignoreKeys.length; i++)
		{
			if(this._ignoreKeys[i] == key)
			{
				this._ignoreKeys.splice(i, 1);
				return true;
			}
		}
	}
	return false;
}

/// <summary>
/// Processes commands sent directly to OSH module.
/// This method tries to parse the command as a key.
/// If succeeded it forwards the key to processKey method for further processing,
/// if not - to processCommand method.
/// </summary>
OSH.prototype.processKeyOrCommandInternal = function(command)
{
	// If command is a key - forward it to another method
	var key = Keys.parseKey(command);
	if(key != 0)
		return this.processKey(key, this, null);
	else
		return this.processCommand(command, this, null);
}

/// <summary>
/// Processes keys sent directly to OSH module or forwarded from other applications.
/// </summary>
/// <param name="key">Key code.</param>
/// <param name="keySource">Optional. The source of the key. Can be used to prevent infinite looping.</param>
/// <param name="srcEvent">window.event object generally passed from window.onKeyDown/window.onKeyPress methods.</param>
/// <returns>Returns true if the key was processed.</returns>
OSH.prototype.processKey = function(key, keySource, srcEvent)
{
	window.top.log.writeln("OSH key: " + key + " source: " + keySource);

	if(this.needToIgnoreKey(key))
	{
		window.top.log.writeln("Ignored");
		return false;
	}

	var e = srcEvent;
	if(!e)
	{
		e = window.top.document.createEventObject();
		e.source = keySource || this;
		e.refreshOSD = true;
		e.processed = false;
	}
	e.keyCode = key;
	
	// Global handlers.
	this.onKey.fire(this, e);

	if(e.processed)
		window.top.log.writeln("OSH key processed by global handler.");

	if(!e.processed)
	{
		// Give a chance to the current screen to process the key.
		if(this.getVisible())
		{
			var screen = Screen.getCurrent();
			if(screen)
				screen.processKey(this, e);
		}

		if(e.processed)
			window.top.log.writeln("OSH key processed by screen handler.");
	}

	if(!e.processed)
	{
		// Give a chance to the current mode to process the key.
		var mode = this.getMode();
		if(mode)
			mode.processKey(this, e);

		if(e.processed)
			window.top.log.writeln("OSH key processed by mode handler.");
	}


	// Refresh OSD if no one canceled it.
	if(!srcEvent && /*e.processed && */ e.refreshOSD)
	{
		this.refresh();
		e.refreshOSD = false;
	}

	return e.processed;
}

/// <summary>
/// Processes commands sent directly to OSH module or forwarded from other applications.
/// This method processes the following commands:
///		"show" - show OSD
///		"hide" - hide OSD
///		"forward:screen:ScreenName" - forwards command to the specified screen.
///		"mode:ModeName" - changes OSH mode
///		"screen:[ScreenName][:Command]"
///            - forwards command to the specified screen (if ScreenName is missing, then used the current screen).
///              If Command is missing it navigates to the "ScreenName" screen.
///		"player:[PlayerName]:Command"
///            - forwards command to the specified player (if PlayerName is missing, then used the current player).
///		         Common supported commands:
///		         Play - starts playing current (of the first) media in the current media tree.
///		         Play:mediaUri - starts playing the media with specified mediaUri.
///		         Pause - pauses/resumes media playback.
///		         Stop - stops media playback.
///		"char:Char" - processes key Char.charCodeAt(0)
///		"media:[Command]"
///		       - forwards command to the MediaControlller. MediaControlller supports the follwing commands:
///		         Next - starts playing the text media in the current media tree
///		         Previous - starts playing the previous media in the current media tree
///		         NextFolder - starts playing the first media in the next folder of the current media tree
///		         PreviousFolder - starts playing the first media in the previous folder of the current media tree
/// </summary>
/// <param name="command">String command.</param>
/// <param name="commandSource">Optional. The source of the command.
/// Can be used to prevent infinite looping.</param>
/// <returns>Returns true if the command was processed.</returns>
OSH.prototype.processCommand = function(command, commandSource, srcEvent)
{
	window.top.log.writeln("OSH command: '" + command + "' source: " + commandSource);

	var e = srcEvent;
	if(!e)
	{
		e = window.top.document.createEventObject();
		e.source = commandSource || this;
		e.refreshOSD = true;
		e.processed = false;
	}
	e.command = command;
	
	// Global handlers.
	this.onCommand.fire(this, e);
	
	if(e.processed)
		window.top.log.writeln("OSH command processed by global handler.");
	
	if(!e.processed)
	{
		this.processOshCommand(command, commandSource, e);

		if(e.processed)
			window.top.log.writeln("OSH command processed.");
	}

	// Refresh OSD if no one canceled it.
	if(!srcEvent && /*e.processed && */ e.refreshOSD)
	{
		this.refresh();
		e.refreshOSD = false;
	}
	
	return e.processed;
}

OSH.prototype.processOshCommand = function(command, commandSource, e)
{
	var schema = "osh";
	if(command.indexOf(":") != -1)
	{
		schema = String.substringBefore(command, ":").toLowerCase();
		command = String.substringAfter(command, ":");
	}
	var commandLowerCase = command.toLowerCase();

	var targetName = String.substringBefore(command, ":");
	var targetCommand = String.substringAfter(command, ":");
	if(!targetCommand)
		targetName = command;


	if(schema == "osh" && command)
	{
		e.processed = true;
		if(commandLowerCase == "show")
			this.show();
		else if(commandLowerCase == "hide")
			this.hide();
	}
	else if(schema == "forward" && command)
	{
		e.processed = true;
		if(targetName.toLowerCase() == "screen")
		{
			var screenName = String.substringBefore(targetCommand, ":");
			var screenCommand = String.substringAfter(targetCommand, ":");
			if(!screenCommand)
			{
				screenName = targetCommand;
				screenCommand = null;
			}

			var screen = (!screenName) ? Screen.getCurrent() : Screen.getScreen(screenName);
			if(screen)
			{
				if(!this.getVisible() || screen != Screen.getCurrent())
				{
					screen.open(screenCommand, e.keyCode);
					this.show();
				}
				else
				{
					alert(1);
					e.command = null;
					screen.processKey(this, e);
					e.command = command;
				}
			}
		}
	}
	else if(schema == "mode" && command)
	{
		e.processed = true;

		this.setMode(command);
	}
	else if(schema == "screen" && command)
	{
		e.processed = true;

		var screenName = targetName;
		var screenCommand = targetCommand;

		var screen = (!screenName) ? Screen.getCurrent() : Screen.getScreen(screenName);
		if(screen)
		{
			e.command = screenCommand;
			screen.processCommand(this, e);
			e.command = command;
		}
	}
	else if(schema == "player" && command)
	{
		e.processed = true;

		var playerName = targetName;
		var playerCommand = targetCommand;

		var player = (!playerName) ?
			this.mediaController.getCurrentPlayer() :
			this.mediaController.getPlayer(playerName);
		if(player)
		{
			window.top.log.writeln("Forwarding command '" + playerCommand + "' to " + player.getName() + "...");

			e.command = playerCommand;
			player.processCommand(this, e);
			e.command = command;
		}
	}
	else if(schema == "char" && command)
	{
		this.processKey(command.charCodeAt(0), commandSource, e);
	}
	else if(schema == "media" && command)
	{
		e.processed = true;
		e.command = command;
		this.mediaController.processCommand(this, e);
	}

	return e.processed;
}


//**********************************************************
// Mode
//**********************************************************
function Mode(name)
{
	var _name = name;
	var _config;
	var _keys;
	
	function initialize()
	{
		_config = getModeConfig(_name);
		_keys = Configuration.readKeysConfig(_config.Keys);
	}
	
	function getModeConfig(/* string */ modeName)
	{
		var modes = new Enumerator(Configuration.getCurrent().Osh.Modes).toArray();
		for(var i = 0; i < modes.length; i++)
			if(modes[i].Name == modeName)
				return modes[i];
		return null;
	}

	this.processKey = function(sender, event)
	{
		window.top.log.writeln(_name + "Mode.processKey(" + event.keyCode + ")");

		if(_keys && event.keyCode)
		{
			var key = _keys[event.keyCode];
			if(key && key.command)
			{
				OSH.getCurrent().processCommand(key.command, event.source, event);
				//event.processed = true;
				//event.refreshOSD = false;
				return;
			}
		}
	}

	initialize();
}
Type.registerType('Mode');

Mode.getMode = function(modeName)
{
	if(!Mode._modes)
		Mode._modes = [];

	var mode = Mode._modes[modeName.toLowerCase()];
	if(!mode)
	{
		mode = new Mode(modeName);
		Mode._modes[modeName.toLowerCase()] = mode;
		Mode._modes.push(mode);
	}
	return mode;
}


//**********************************************************
// Screen
//**********************************************************
function Screen(_name)
{
	var _this = this;
	var _osh = OSH.getCurrent();
	this.url = "/Screens/" + _name + ".html";
	var _autoHideInterval = 0;
	this.arguments = null;

	var _forwardKey;
	var _loaded = false;
	var _frame = null;
	this.backKey = 0;
	this.keys = null;
	
	var _config = getScreenConfig(_name);
	if(_config)
	{
		_name = _config.Name;

		this.backKey = Keys.parseKey(_config.BackKey);

		_autoHideInterval = _config.AutoHideInterval;

		this.keys = Configuration.readKeysConfig(_config.Keys);
	}

	// Events
	this.onLoad = new Event();
	this.onUnload = new Event();
	this.onShow = new Event();
	this.onHide = new Event();
	this.onAutoHide = new Event();
	this.onKeyPreview = new Event();
	this.onKey = new Event();
	this.onCommand = new Event();

	this.commandHandler = new CommandHandler(this);
	
	var _autoHideTimer = new Timer("Screen.autoHideTimer", _autoHideInterval);
	_autoHideTimer.setAutoReset(false);

	var _delayedShowTimer = new Timer("Screen.delayedShowTimer", 100);
	_delayedShowTimer.setAutoReset(false);

	function initialize()
	{
		_autoHideTimer.onTimeout.attach(_this, _this.onAutoHideTimeout);
		_delayedShowTimer.onTimeout.attach(_this, _this.show);
		
		_osh.onShow.attach(null, Screen._onOSHShow);
		_osh.onHide.attach(null, Screen._onOSHHide);
	}
	
	function getScreenConfig(/* string */ screenName)
	{
		var screens = new Enumerator(Configuration.getCurrent().Osh.Screens).toArray();
		for(var i = 0; i < screens.length; i++)
			if(screens[i].Name == screenName)
				return screens[i];
		return null;
	}

	this.getName = function()
	{
		return _name;
	}

	this.isNavigationRoot = function()
	{
		return _name.toLowerCase() == "home";
	}

	this.getFrame = function()
	{
		if(_frame == null)
		{
			_loaded = false;
			_frame = window.top.document.createElement("iframe");
			_frame.id = _name;
			_frame.screen = this;
			_frame.className = "screen";
			_frame.allowTransparency = true;
			_frame.attachEvent("onload", Screen._onScreenFrameLoad);
			_frame.src = this.url;
			_frame.style.visibility = "hidden";
		}
		
		return _frame;
	}

	this.getVisible = function()
	{
		var frame = this.getFrame();
		return frame && frame.style.visibility == "visible"
	}

	function isLoading()
	{
		return _frame != null;
	}

	function isLoaded()
	{
		if(_loaded)
			return true;
		
		var doc = _this.getDocument();
		if(!doc)
			return false;

		_loaded = doc.readyState == "complete";
		return _loaded;
	}

	this.getDocument = function()
	{
		if(_frame == null)
			return null;

		var frame = window.top.frames(_frame.id);
		if(frame)
			return frame.document;
	}

	this.open = function(args, keyCode)
	{
		_osh.navigator.go(this, { args: args, keyCode: keyCode });
	}

	// Don't call this function directly.
	// For osh.navigator use only.
	this.openInternal = function(args)
	{
		window.top.log.writeln(_name + ".openInternal()");

		this.arguments = args ? args.args : null;
		_forwardKey = args ? args.keyCode : null;

		_osh.suspendLayout(); // will be resumed in the end of show() method

		var frame = this.getFrame();
		if(frame.parentElement == null)
		{
			var screenBox = Screen.getScreenBox();
			screenBox.appendChild(frame); // append will start loading the frame source
			// When the frame is loaded onScreenFrameLoad() method will be called
		}
		else
		{
			this.show();
		}
	}

	this.close = function()
	{
		_osh.navigator.back();
	}

	this.show = function()
	{
		window.top.log.writeln(_name + ".show()");

		for(var i = 0; i < Screen._screens.length; i++)
		{
			var screen = Screen._screens[i];
			if(screen != this)
				screen.hide();
		}
		Screen._current = this;
		_osh.notifyScreenChange(_name);

		if(this.getVisible())
		{
			_osh.resumeLayout(); // was suspended in openInternal() method
			this.restartAutoHideTimer();
			return;
		}
		
		this.getFrame().style.visibility = "visible";
		fireOnShow();
		this.restartAutoHideTimer();
		this.forwardKey();

		_osh.refresh(); // refresh in case the screen was open not as a result of a key press or command
		
		_osh.resumeLayout(); // was suspended in openInternal() method
	}

	this.hide = function()
	{
		if(!this.getVisible())
			return;

		window.top.log.writeln(_name + ".hide()");

		_autoHideTimer.stop();
		var frame = this.getFrame();
		if(frame)
			frame.style.visibility = "hidden";
		fireOnHide();
	}

	this.stopAutoHideTimer = function()
	{
		_autoHideTimer.stop();
	}

	this.restartAutoHideTimerIfRunning = function()
	{
		if(_autoHideTimer.getEnabled())
			this.restartAutoHideTimer();
	}

	this.restartAutoHideTimer = function(autoHideInterval)
	{
		if(autoHideInterval)
			_autoHideTimer.setInterval(autoHideInterval);
		else
			_autoHideTimer.setInterval(_autoHideInterval);
		_autoHideTimer.restart();
	}

	this.processKey = function(sender, event)
	{
		window.top.log.writeln(_name + ".processKey(" + event.keyCode + ")");

		if(this.backKey == event.keyCode)
		{
			_osh.navigator.back();
			event.processed = true;
			//event.refreshOSD = false;
			return;	
		}

		if(!this.needToProcess(event.keyCode))
		{
			//event.processed = false;
			//event.refreshOSD = false;
			return;
		}

		if(this.keys && event.keyCode)
		{
			var key = this.keys[event.keyCode];
			if(key && key.command)
			{
				_osh.processCommand(key.command, event.source, event);
				//event.processed = true;
				//event.refreshOSD = false;
				return;
			}
		}
		
		this.restartAutoHideTimerIfRunning();

		this.onKeyPreview.fire(this, event);
		if(!event.processed)
		{
			this.commandHandler.processKey(this, event);
			if(!event.processed)
			{
				event.processed = true;
				this.onKey.fire(this, event);
			}
		}
	}

	this.processCommand = function(sender, event)
	{
		window.top.log.writeln(_name + ".processCommand('" + event.command + "')");

		if(!event.command)
		{
			_osh.navigator.go(this.getName());
			_osh.show();
		}
		else
		{
			if(!isLoaded())
			{
				if(isLoading())
					return;

				this.open(event.command);
				return;
			}
			this.restartAutoHideTimerIfRunning();
			this.onCommand.fire(this, event);
		}
	}

	this.needToProcess = function(keyCode)
	{
		if(!keyCode) return false;
		
		if(this.keys)
		{
			var key = this.keys[keyCode];
			return !!key;
		}
		else
			return true;
	}

	this.onScreenFrameLoad = function()
	{
		// Gives time to some filters (like AplphaPNG) to apply.
		_delayedShowTimer.restart(); // after delay the show() method will be called

		// Refresh controls tree.
		this.commandHandler.refresh();

		fireOnLoad();
		this.forwardKey();
	}

	this.onScreenFrameUnload = function()
	{
		window.top.log.writeln(_name + ".onScreenFrameUnload()");
		this.hide();
		fireOnUnload();
	}

	this.onOSHShow = function()
	{
		window.top.log.writeln(_name + ".onOSHShow()");

		_osh.suspendLayout();
		fireOnShow();
		this.restartAutoHideTimer();
		this.forwardKey();
		_osh.refresh();
		_osh.resumeLayout();
	}

	this.onOSHHide = function()
	{
		window.top.log.writeln(_name + ".onOSHHide()");

		_autoHideTimer.stop();
		fireOnHide();
	}

	this.onAutoHideTimeout = function(sender, event)
	{
		window.top.log.writeln(_name + ".onAutoHideTimeout()");

		if(!this.getVisible())
			return;

		fireOnAutoHide();
		_osh.hide();
		// onHide event will be fired in Screen._onOSHHide method
	}

	this.forwardKey = function()
	{
		if(!_forwardKey) return;
		if(!isLoaded()) return;

		var e = window.top.document.createEventObject();
		e.keyCode = _forwardKey;
		_forwardKey = null;
		this.processKey(this, e);
	}

	function fireOnLoad()
	{
		var e = window.top.document.createEventObject();
		_this.onLoad.fire(_this, e);
	}

	function fireOnUnload()
	{
		var e = window.top.document.createEventObject();
		_this.onUnload.fire(_this, e);
	}

	function fireOnShow()
	{
		var e = window.top.document.createEventObject();
		_this.onShow.fire(_this, e);
	}

	function fireOnHide()
	{
		var e = window.top.document.createEventObject();
		_this.onHide.fire(_this, e);
	}

	function fireOnAutoHide()
	{
		var e = window.top.document.createEventObject();
		_this.onAutoHide.fire(_this, e);
	}
	
	initialize();
}
Type.registerType('Screen');



//**********************************************************
// Static members
//**********************************************************

Screen._current = null;
Screen.getCurrent = function()
{
	return Screen._current;
}

Screen._screens = new Array();
Screen.getScreen = function(/* string */ screenName)
{
	var screen = Screen._screens[screenName.toLowerCase()];
	if(screen != null)
		return screen;

	var screen = new Screen(screenName);
	Screen._screens[screenName.toLowerCase()] = screen;
	Screen._screens.push(screen);

	return screen;
}

Screen.getScreenByHref = function(/* string */ href)
{
	var screenName = href.substring(href.lastIndexOf("/") + 1, href.lastIndexOf("."));
	return Screen.getScreen(screenName);
}

Screen.getScreenBox = function()
{
	return window.top.document.getElementById("screenBox");
}


//**********************************************************
// Global event handlers
//**********************************************************
Screen._onScreenFrameLoad = function()
{
	window.top.document.frames(event.srcElement.id).document.attachEvent("onunload", Screen._onScreenFrameUnload);
	event.srcElement.screen.onScreenFrameLoad();
}

Screen._onScreenFrameUnload = function()
{
	window.top.log.writeln("Screen._screenFrameOnUnload()");
	event.srcElement.window.screen.onScreenFrameUnload();
}

Screen._onOSHShow = function()
{
	var currentScreen = Screen.getCurrent();
	if(currentScreen)
		currentScreen.onOSHShow();
}

Screen._onOSHHide = function()
{
	var currentScreen = Screen.getCurrent();
	if(currentScreen)
		currentScreen.onOSHHide();
}




//**********************************************************
// Navigator
//**********************************************************
function Navigator()
{
	this.history = [];
}

Navigator.prototype.go = function(/* string / Screen */ screen, /* object */ args, /* bool */ saveInHistory /* = true */)
{
	if(typeof(screen) == "string")
		screen = Screen.getScreen(screen);

	if(saveInHistory == null)
		saveInHistory = true;

	if(screen.isNavigationRoot())
		this.history = [];

	screen.openInternal(args);
	
	if(saveInHistory)
		this.history.push(screen.getName());
}

Navigator.prototype.back = function()
{
	if(this.history.length <= 1)
		return;
	
	this.history.pop();
	var screenName = this.history[this.history.length - 1];
	var screen = Screen.getScreen(screenName);

	screen.openInternal(null);
}
Type.registerType('Navigator');



